package com.db.sevent;
/**
* @author 作者:秋哲    E-mail:2810201146@qq.com:
* @version 创建时间：2020年5月22日 下午6:32:25
* @description: 
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import org.junit.Test;
import com.component.GetNewGroup;
import com.db.service.GroupServer;
import com.view.P1;

public class GroupEvent {
	//初始化
	public void initGroupList() {
		DefaultComboBoxModel<String> dataByGui = new GroupServer().updateDataGroupList();
		P1.instance.com01.setModel(dataByGui);
	}
	// 新建组
	@Test
	public void newGeoup() {
		GetNewGroup newGroupGUI = new GetNewGroup();
		newGroupGUI.setVisible(true);
		newGroupGUI.setTitle("新建组");
		newGroupGUI.textField_1.setText("");
		newGroupGUI.textArea.setEnabled(false);
		newGroupGUI.btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String title = newGroupGUI.textField_1.getText();
				int insert = new GroupServer().insertWorkGroup(title);
				if(insert==1) {
					System.out.println("添加成功");
					new GroupEvent().initGroupList();
				}else {
					System.out.println("添加失败："+title);
				}
			}
		});
	}
	//删除组
	public void deleteWorkGroup() {
		String GUIComText =(String) P1.instance.com01.getSelectedItem();
		GroupServer server = new GroupServer();
		int n = server.deleteWorkGroup(GUIComText);
		if(n==1) {
			System.out.println("删除成功");
			this.initGroupList();
		}else {
			System.out.println("删除失败");
		}
	}
	//修改组
	public void updateGroup(){
		GetNewGroup newGroupGUI = new GetNewGroup();
		newGroupGUI.setVisible(true);
		newGroupGUI.setTitle("修改作业");
		String GUIComText = (String) P1.instance.com01.getSelectedItem();
		newGroupGUI.textField_1.setText(GUIComText);
		newGroupGUI.textArea.setEnabled(false);
		newGroupGUI.btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String GUIComNewText = newGroupGUI.textField_1.getText();
				String GUIComText = (String) P1.instance.com01.getSelectedItem();
				int n = new GroupServer().updateWorlGroup(GUIComText, GUIComNewText);
				if(n==1) {
					System.out.println("修改成功");
					new GroupEvent().initGroupList();
				}else {
					System.out.println("修改失败");
				}
			}
		});
	}
}
